home *** CD-ROM | disk | FTP | other *** search
- ;**************************************************************
- ;
- ; fl_add.asm
- ;
- ; staff
- ;
- ; 02-21-91
- ;
- ; (C) Texas Instruments Inc., 1992
- ;
- ; Refer to the file 'license.txt' included with this
- ; this package for usage and license information.
- ;
- ;**************************************************************
-
- .title "Floating Point Addition Algorithm"
- .def FL_ADD
-
- * INPUT FORMAT
- * ============
- * ----------------
- * | ALL 0 OR 1 | SIGN WORD
- * ----------------
- *
- * ----------------
- * | 16 BITS | EXPONENT
- * ----------------
- *
- * ----------------
- * |0| 15 BITS | HIGH PART OF MANTISSA
- * ----------------
- *
- * ----------------
- * |0| 9 BITS |-0-| LOW PART OF MANTISSA
- * ----------------
- *
- * OUTPUT FORMAT
- * =============
- * SAME AS INPUT FORMAT EXCEPT THAT LOW PART OF MANTISSA HAS
- * 16 VALID BITS INSTEAD OF HAVING A ZERO MSB.
-
-
-
-
- TREG1 .set 0dh
-
- ASIGN .set 60h ;Sign, exponent, high and low part of mantissa
- AEXP .set 61h ;of input number A
- AHI .set 62h
- ALO .set 63h
-
- BSIGN .set 64h ;Sign, exponent, high and low part of mantissa
- BEXP .set 65h ;of input number B
- BHI .set 66h
- BLO .set 67h
-
- CSIGN .set 68h ;Sign, exponent, high and low part of mantissa
- CEXP .set 69h ;of the resuting floating point number C
- CHI .set 6Ah
- CLO .set 6Bh
- DIFFEXP .set 6Ch
-
- .text
-
- FL_ADD LDP #0 ;Initialization
- SETC SXM
- MAR *,AR0
- LAR AR0,0 ;AR0 is used by NORM instruction
- LACC ALO,1 ;Get rid of 0 MSBs in
- SACL ALO ;low part of numbers
- LACC BLO,1
- SACL BLO
-
- CMPEXP LACL BLO
- ADD BHI,16
- SACB ;AccB = BHIBLO
- LACC AEXP
- SUB BEXP
- SACL DIFFEXP ;Save the difference
- BCND AEQB,EQ ;If |A| == |B|
- BCND ALTB,LT ;If |A| < |B|
-
- AGTB LACC DIFFEXP ;If |A| > |B|
- SAMM TREG1
- SUB #32
- BCND AGRT32,GEQ ;If difference > 32
- LACB ;Acc = BHIBLO
- SATL
- SATH ;Right justify BHIBLO
- SACB ;Store the result back in AccB
-
- AEQB LACC ASIGN ;Copy sign and exponent values of
- SACL CSIGN ;A in C (i.e. the result)
- LACC AEXP
- SACL CEXP
-
- CHKSGN LACC ASIGN
- SUB BSIGN
- CLRC TC ;Clear TC flag
- XC 1,LT
- SETC TC ;Set TC flag if A<0 and B>0
- BCNDD ADNOW,EQ ;If both A and B have same sign
- LACL ALO
- ADD AHI,16 ;Acc = AHIALO
- SBB ;Acc=A-B
- XC 1,TC ;If A<0 and B>0
- NEG ;then Acc=B-A
- BCND CZERO,EQ ;If A-B == 0
- XC 2,LT ;If A-B < 0
- SPLK #0FFFFH,CSIGN ; then CSIGN=-1
- XC 2,GT ;If A-B > 0
- SPLK #0,CSIGN ; then CSIGN=0
- XC 1,LT
- ABS
- BD NORMAL
- SACH CHI ;Save the result
- SACL CLO
-
- CZERO LACC #0 ;If A-B == 0
- SACL CEXP ;then result is zero
- SACL CSIGN
- RETD ;Return
- SACL CHI
- SACL CLO
-
- ADNOW ADDB ;If signs are same
- BCNDD OVFLOW,OV ;then add two numbers
- SACH CHI
- SACL CLO
- BCND CZERO,EQ
-
- NORMAL CPL #0,CHI
- NOP ;Dead cycle for XC
- XC 2,TC ;If CHI is 0
- LACC CLO,16 ;then normalize only the CLO part
- LAR AR0,16 ;AR0 has exponent value
- XC 2,NTC ;If CHI != 0
- LACC CHI,16 ;Acc=CHICLO
- ADDS CLO
- CLRC SXM
- XC 2,LT ;If MSB of CLO is 1
- SBRK 1 ;then shift right once
- SFR ;and decrement exponent.
- SETC SXM
- RPT #13
- NORM *+ ;Normalize
-
- OUTPUT SACH CHI
- SACL CLO ;Store the result
- LACC CEXP
- SAR AR0,CEXP
- RETD ;Return
- SUB CEXP
- SACL CEXP ;CEXP=CEXP-AR0
-
- OVFLOW CLRC SXM
- SFR
- SACH CHI
- SACL CLO
- LACC CEXP
- ADD #1
- SACL CEXP
-
- ALTB LACC BSIGN ;Copy sign and exponent of B in C
- SACL CSIGN
- LACC BEXP
- SACL CEXP
- LACC DIFFEXP
- NEG ;since A-B < 0 here
- SAMM TREG1 ;No. of shifts reqd. for right-justification
- SUB #32
- BCND BGRT32,GEQ ;difference in exponent >= 32
- LACL ALO
- ADD AHI,16
- SATL
- SATH ;Right-justify ALOAHI
- BD CHKSGN ;Jump back
- SACL ALO
- SACH AHI
-
- BGRT32 LACC BHI ;If exponent of B > 32
- SACL CHI ;then C <- B.
- RETD ;Return
- LACC BLO
- SACL CLO
-
- AGRT32 LACC AHI ;If exponent of A > 32
- SACL CHI ;then C <- A.
- LACC ALO
- SACL CLO
- LACC ASIGN
- SACL CSIGN
- RETD ;Return
- LACC AEXP
- SACL CEXP